/* GUI CONVERTED from rcsqsciq.p (converter v1.76) Fri May  3 13:22:37 2002 */
/* rcsqsciq.p - CUSTOMER SEQUENCE SCHEDULE INQUIRY                            */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.8 $                                                           */
/*V8:ConvertMode=Report                                                       */
/* REVISION: 9.1      CREATED:       06/08/99     BY: *N003* Dan Herman       */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00     BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00     BY: *N0KP* myb              */
/* $Revision: 1.8 $    BY: Katie Hilbert         DATE: 04/15/02  ECO: *P03J*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */
/*         THIS PROGRAM IS A BOLT-ON TO STANDARD PRODUCT MFG/PRO.           */
/* ANY CHANGES TO THIS PROGRAM MUST BE PLACED ON A SEPARATE ECO THAN        */
/* STANDARD PRODUCT CHANGES.  FAILURE TO DO THIS CAUSES THE BOLT-ON CODE TO */
/* BE COMBINED WITH STANDARD PRODUCT AND RESULTS IN PATCH DELIVERY FAILURES.*/
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i "2+ "}

define new shared variable ship-param1 as character no-undo.
define new shared variable ship-param2 as character no-undo.
define variable l_shipfrom       like rcs_shipfrom  no-undo.
define variable l_shipto         like rcs_shipto    no-undo.
define variable l_err_stat       like mfc_logical   no-undo.
define variable l_shipname       like ad_name       no-undo.
define variable l_sitename       like si_desc       no-undo.
define variable l_start_cust_job like rcsd_cust_job no-undo.
define variable l_start_cust_seq like rcsd_cust_seq no-undo.
define variable l_start_date     like rcsd_date     no-undo.
define variable l_rlse_id        like rcs_rlse_id   no-undo.

/* FRAME A: SELECTION FORM */


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
rcs_shipfrom      colon 25
   l_sitename        no-label
   rcs_shipto        colon 25
   l_shipname        no-label
   rcs_rlse_id       colon 25
   rcs_active        colon 70
   skip(1)
   l_start_cust_job  colon 25  label "Starting Job"
   l_start_cust_seq  colon 25  label "Starting Sequence"
   l_start_date      colon 25  label "Starting Date"
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

FORM /*GUI*/ 
   rcs_shipfrom      colon 25
   l_sitename        no-label
   rcs_shipto        colon 25
   l_shipname        no-label
   rcs_rlse_id       colon 25
   rcs_active        colon 70
with STREAM-IO /*GUI*/  frame a1 side-labels width 80 attr-space
   title color normal
   (getFrameTitle("CUSTOMER_SEQUENCE_SCHEDULE",34)).

/* SET EXTERNAL LABELS */
setFrameLabels(frame a1:handle).

/* FRAME B: DISPLAY FORM */

FORM /*GUI*/ 
   rcs_cr_date           colon 25
   rcs_cr_time           no-label
   rcs_cumulative        colon 25
   rcs_packing_order     colon 25
   rcs_seq_per_container colon 25
   rcs_check_seq_tol     colon 25
   rcs_max_tol           colon 25
   rcs_date_type         colon 25
   rcs_active_start      colon 25
   rcs_active_end        colon 25
with STREAM-IO /*GUI*/  frame b side-labels width 80 attr-space.

/* SET EXTERNAL LABELS */
setFrameLabels(frame b:handle).

/* FRAME C: DISPLAY FORM */

FORM /*GUI*/ 
   rcsd_date         colon 25
   rcsd_time
   rcsd_cust_job     colon 25
   rcsd_cust_seq     colon 25
   rcsd_order        colon 25
   rcsd_line         colon 45
   pt_um             colon 72
   rcsd_part         colon 25
   pt_desc1          no-label
   rcsd_cust_po      colon 25
   rcsd_custref      colon 25 label "Line Item Customer Ref"
   rcsd_modelyr      colon 72
   rcsd_cust_ref     colon 25
   rcsd_dock         colon 25
   rcsd_picked       colon 72
   rcsd_line_feed    colon 25
   rcsd_x_referenced colon 72 label "X-Ref"
   skip (1)
   rcsd_discr_qty    colon 25
   rcsd_cum_qty      colon 60
   rcsd_cust_part    colon 25
   rcsd_cust_build_date
   colon 25
   rcsd_status       colon 45
   rcsd_deleted      colon 65
               skip(2)       
with STREAM-IO /*GUI*/  frame c side-labels width 80 attr-space
   title color normal (getFrameTitle("SEQUENCE_DETAIL_DATA",26)) .

/* SET EXTERNAL LABELS */
setFrameLabels(frame c:handle).

/* DISPLAY */

view frame a.

/* PROMPT-FOR KEYS */
mainloop:
repeat with frame a:
   assign
      l_sitename = ""
      l_shipname = "".

   display
      l_sitename
      l_shipname
   with frame a.

   hide frame a1.
   hide frame b.
   hide frame c.

   if l_start_date = low_date then l_start_date = ?.

   prompt-for
      rcs_shipfrom
      rcs_shipto
      rcs_rlse_id
      l_start_cust_job
      l_start_cust_seq
      l_start_date
      with frame a
   editing:

      if frame-field = "rcs_shipfrom" or
         frame-field = "rcs_shipto"   or
         frame-field = "rcs_rlse_id" then do:

         assign
            ship-param1 = input frame a rcs_shipfrom
            ship-param2 = input frame a rcs_shipto.

         {gpbrparm.i &browse=rclu104.p &parm=c-brparm1 &val=ship-param1}
         {gpbrparm.i &browse=rclu104.p &parm=c-brparm2 &val=ship-param2}

         {mfnp08.i rcs_mstr
            rcs_index1
            "rcs_shipfrom <> ''"
            rcs_shipfrom
            "input rcs_shipfrom"
            rcs_shipto
            "input rcs_shipto"
            rcs_rlse_id
            "input rcs_rlse_id"
            }

         if recno <> ? then do:
            assign
               ship-param1 = rcs_shipfrom
               ship-param2 = rcs_shipto.

            {gpbrparm.i &browse=rclu104.p &parm=c-brparm1 &val=ship-param1}
            {gpbrparm.i &browse=rclu104.p &parm=c-brparm2 &val=ship-param2}

            run get_site_name
               (input rcs_shipfrom, output l_sitename).

            run get_ship_name
               (input rcs_shipto, output l_shipname).

            display
               rcs_shipfrom
               l_sitename
               rcs_shipto
               l_shipname
               rcs_rlse_id
               rcs_active
            with frame a.
         end.  /* if recno <> ? */
      end. /* IF FRAME-FIELD */

      else do:

         assign
            ship-param1 = input frame a rcs_shipfrom
            ship-param2 = input frame a rcs_shipto.

         {gpbrparm.i &browse=rclu104.p &parm=c-brparm1 &val=ship-param1}
         {gpbrparm.i &browse=rclu104.p &parm=c-brparm2 &val=ship-param2}

         readkey.
         apply lastkey.

      end.

   end. /* PROMPT-FOR EDITING */

   assign
      l_shipfrom = input frame a rcs_shipfrom
      l_shipto   = input frame a rcs_shipto
      l_rlse_id  = input frame a rcs_rlse_id
      l_start_cust_job = input frame a l_start_cust_job
      l_start_cust_seq = input frame a l_start_cust_seq
      l_start_date = input frame a l_start_date.

   /* VALIDATE SHIPFROM */
   run val_shipfrom
      (input l_shipfrom,
       output l_err_stat).

   if l_err_stat then do:
      if c-application-mode = 'web' then return.
      next-prompt rcs_shipfrom with frame a.
      undo, retry.
   end.

   run get_site_name
      (input l_shipfrom, output l_sitename).
   display l_sitename with frame a.

   /* VALIDATE SHIPTO */
   run validate_shipto
      (input l_shipto,
       output l_err_stat).

   if l_err_stat then do:
      if c-application-mode = 'web' then return.
      next-prompt rcs_shipto with frame a.
      undo, retry.
   end.

   run get_ship_name
      (input l_shipto, output l_shipname).
   display l_shipname with frame a.

   assign
      ship-param1 = l_shipfrom
      ship-param2 = l_shipto.
   {gpbrparm.i &browse=rclu104.p &parm=c-brparm1 &val=ship-param1}
   {gpbrparm.i &browse=rclu104.p &parm=c-brparm2 &val=ship-param2}

   for first rcs_mstr where
      rcs_shipfrom = l_shipfrom and
      rcs_shipto  = l_shipto  and
      (if l_rlse_id = "" then rcs_active else
      rcs_rlse_id = l_rlse_id)
   no-lock:
   end.

   if not available (rcs_mstr)  and l_rlse_id = "" then do:
      {pxmsg.i &MSGNUM=2362 &ERRORLEVEL=3} /*ACTIVE SCHEDULE DOES NOT EXIST*/
      if c-application-mode = 'web' then return.
      next-prompt rcs_rlse_id with frame a.
      undo, retry.
   end.  /* if not available (rcs_mstr) */

   else
   if not available (rcs_mstr) then do:
      {pxmsg.i &MSGNUM=6013 &ERRORLEVEL=3} /*SCHEDULE DOES NOT EXIST*/
      if c-application-mode = 'web' then return.
      next-prompt rcs_rlse_id with frame a.
      undo, retry.
   end.  /* Else if not available (rcs_mstr) */

   assign
      l_rlse_id = rcs_rlse_id.

   display
      rcs_rlse_id
      rcs_active
   with frame a.

   /* OUTPUT DESTINATION SELECTION */
   {gpselout.i &printType = "terminal"
               &printWidth = 80
               &pagedFlag = " "
               &stream = " "
               &appendToFile = " "
               &streamedOutputToTerminal = " "
               &withBatchOption = "no"
               &displayStatementType = 1
               &withCancelMessage = "yes"
               &pageBottomMargin = 6
               &withEmail = "yes"
               &withWinprint = "yes"
               &defineVariables = "yes"}
/*GUI*/ RECT-FRAME:HEIGHT-PIXELS in frame a = FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.


   ststatus = stline[2].
   status input ststatus.

   if l_start_date = ? then l_start_date = low_date.
   for first rcs_mstr
      where rcs_shipfrom = l_shipfrom
        and rcs_shipto   = l_shipto
        and rcs_rlse_id  = l_rlse_id
   no-lock:

   hide frame a.
   display
      rcs_shipfrom
      l_sitename
      rcs_shipto
      l_shipname
      rcs_rlse_id
      rcs_active
   with frame a1 STREAM-IO /*GUI*/ .

   display
      rcs_cr_date
      rcs_cr_time
      rcs_cumulative
      rcs_packing_order
      rcs_seq_per_container
      rcs_check_seq_tol
      rcs_max_tol
      rcs_date_type
      rcs_active_start
      rcs_active_end
   with frame b STREAM-IO /*GUI*/ .

   /* VERIFY RECORDS EXIST USING STARTING FIELD VALUES */
   if not can-find (first rcsd_det where
      rcsd_shipfrom =  rcs_shipfrom       and
      rcsd_shipto   =  rcs_shipto         and
      rcsd_rlse_id  =  rcs_rlse_id        and
      rcsd_cust_job >= l_start_cust_job   and
      rcsd_cust_seq >= l_start_cust_seq   and
      rcsd_date     >= l_start_date
      use-index rcsd_index2) then
      next.

   hide frame b.

   for each rcsd_det    where
         rcsd_shipfrom =  rcs_shipfrom       and
         rcsd_shipto   =  rcs_shipto         and
         rcsd_rlse_id  =  rcs_rlse_id        and
         rcsd_cust_job >= l_start_cust_job   and
         rcsd_cust_seq >= l_start_cust_seq   and
         rcsd_date     >= l_start_date
         use-index rcsd_index2 no-lock with frame c down:

      for first pt_mstr
         fields ( pt_desc1 pt_um )
         where pt_part = rcsd_part no-lock:
      end. /* FOR FIRST PT_MSTR */

      
/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/


      display
         rcsd_date
         rcsd_time
         rcsd_cust_job
         rcsd_cust_seq
         rcsd_order
         rcsd_line
         pt_um               when (available pt_mstr)
         rcsd_part
         pt_desc1            when (available pt_mstr)
         rcsd_cust_po
         rcsd_custref
         rcsd_modelyr
         rcsd_cust_ref
         rcsd_dock
         rcsd_picked
         rcsd_line_feed
         rcsd_x_referenced
         rcsd_discr_qty
         rcsd_cum_qty        when (rcs_cumulative)
         rcsd_cust_part
         rcsd_cust_build_date
         rcsd_status
         rcsd_deleted
          WITH STREAM-IO /*GUI*/ .

      /* THIS CODE IS NEED TO MAKE THE LAST RECORD APPEAR */
      /* ON THE 'TERMINAL'.  ALL OTHER OUTPUTS ARE OK.    */
      /*      -- LOGIC TAKEN FROM arcsiq.p --             */
      if (frame-line(c) = frame-down(c)) and dev = "terminal"
         then pause.

      down.

   end.
   hide frame a1.
end. /* FOR FIRST RCS_MSTR */
{mfreset.i}
/*GUI*/ {mfgrptrm.i} /*Report-to-Window*/

{pxmsg.i &MSGNUM=8 &ERRORLEVEL=1}
end. /* MAIN LOOP */

status input.

PROCEDURE get_ship_name:
   define input parameter ip_rcs_shipto like rcs_shipto no-undo.
   define output parameter op_shipname like ad_name no-undo.

   for first ad_mstr no-lock
      where ad_addr = ip_rcs_shipto:
      op_shipname = ad_name.
   end.
END PROCEDURE. /*get_ship_name*/

PROCEDURE get_site_name:
   define input parameter ip_from like rcs_shipfrom no-undo.
   define output parameter op_sitename like si_desc no-undo.

   for first si_mstr no-lock
      where si_site = ip_from:
      op_sitename = si_desc.
   end.
END PROCEDURE. /*get_site_name*/

PROCEDURE val_shipfrom:
   define input parameter ip_shipfrom like rcs_shipfrom no-undo.
   define output parameter op_error as logical no-undo.

   op_error = false.

   if ip_shipfrom = "" then do:
      {pxmsg.i &MSGNUM=40 &ERRORLEVEL=3}.  /* BLANK NOT ALLOWED */
      op_error = true.
      leave.
   end.

   for first si_mstr where si_site = ip_shipfrom no-lock:
   end.

   if not available si_mstr then do:
      {pxmsg.i &MSGNUM=708 &ERRORLEVEL=3} /* SITE DOES NOT EXIST */
      op_error = true.
      leave.
   end.

END PROCEDURE. /*val_shipfrom*/

PROCEDURE validate_shipto:
   /* SIMILAR TO rcshhdr.i, BUT WEB-ENABLED AND W/O EXTRA CODE */
   define input  parameter shipto like abs_shipto no-undo.
   define output parameter err as logical no-undo.

   define variable addr like ad_addr no-undo.

   err = false.

   for first ls_mstr where ls_addr = shipto
      and (ls_type = "customer"
        or ls_type = "ship-to"
        or ls_type = "dock") no-lock:
   end.

   for first ad_mstr where
      ad_addr = shipto no-lock:
   end.

   if not available ls_mstr or
      not available ad_mstr then do:
      /* NOT A VALID CUSTOMER OR SHIP-TO */
      {pxmsg.i &MSGNUM=8129 &ERRORLEVEL=3}
      err = true.
      leave.
   end.

   for first cm_mstr where
      cm_addr = shipto no-lock:
   end.

   do while not available cm_mstr and ad_ref > "":
      addr = ad_ref.
      for first ad_mstr where
         ad_addr = addr no-lock:
      end.
      for first cm_mstr where
         cm_addr = ad_addr no-lock:
      end.
   end.

   if not available cm_mstr then do:
      /* NOT A VALID CUSTOMER OR SHIP-TO */
      {pxmsg.i &MSGNUM=8129 &ERRORLEVEL=3}
      err = true.
      leave.
   end.

   if cm_cr_hold then do:
      {pxmsg.i &MSGNUM=614 &ERRORLEVEL=2}  /* CUSTOMER ON CREDIT HOLD */
   end.
END PROCEDURE. /* validate_shipto */
